home *** CD-ROM | disk | FTP | other *** search
- package javax.swing.plaf.basic;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.LayoutManager;
- import java.awt.Rectangle;
- import java.awt.event.ActionListener;
- import java.awt.event.FocusListener;
- import java.awt.peer.ComponentPeer;
- import java.awt.peer.LightweightPeer;
- import java.beans.PropertyChangeListener;
- import javax.swing.JComponent;
- import javax.swing.JSplitPane;
- import javax.swing.KeyStroke;
- import javax.swing.LookAndFeel;
- import javax.swing.RepaintManager;
- import javax.swing.UIManager;
- import javax.swing.plaf.ComponentUI;
- import javax.swing.plaf.SplitPaneUI;
-
- public class BasicSplitPaneUI extends SplitPaneUI {
- protected static final String NON_CONTINUOUS_DIVIDER = "nonContinuousDivider";
- protected static int KEYBOARD_DIVIDER_MOVE_OFFSET = 3;
- protected JSplitPane splitPane;
- protected BasicHorizontalLayoutManager layoutManager;
- protected BasicSplitPaneDivider divider;
- protected PropertyChangeListener propertyChangeListener;
- protected FocusListener focusListener;
- protected int dividerSize;
- protected Component nonContinuousLayoutDivider;
- protected boolean draggingHW;
- protected int beginDragDividerLocation;
- protected KeyStroke upKey;
- protected KeyStroke downKey;
- protected KeyStroke leftKey;
- protected KeyStroke rightKey;
- protected KeyStroke homeKey;
- protected KeyStroke endKey;
- protected KeyStroke dividerResizeToggleKey;
- private KeyStroke kpUpKey;
- private KeyStroke kpDownKey;
- private KeyStroke kpLeftKey;
- private KeyStroke kpRightKey;
- protected ActionListener keyboardUpLeftListener;
- protected ActionListener keyboardDownRightListener;
- protected ActionListener keyboardHomeListener;
- protected ActionListener keyboardEndListener;
- protected ActionListener keyboardResizeToggleListener;
- private int orientation;
- private int lastDragLocation;
- private boolean continuousLayout;
- private boolean dividerKeyboardResize;
- private boolean dividerLocationIsSet;
-
- // $FF: synthetic method
- static int access$0(BasicSplitPaneUI var0) {
- return var0.orientation;
- }
-
- // $FF: synthetic method
- static void access$1(BasicSplitPaneUI var0, int var1) {
- var0.orientation = var1;
- }
-
- // $FF: synthetic method
- static boolean access$2(BasicSplitPaneUI var0) {
- return var0.dividerKeyboardResize;
- }
-
- // $FF: synthetic method
- static void access$3(BasicSplitPaneUI var0, boolean var1) {
- var0.dividerKeyboardResize = var1;
- }
-
- // $FF: synthetic method
- static boolean access$4(BasicSplitPaneUI var0) {
- return var0.dividerLocationIsSet;
- }
-
- public BasicSplitPaneDivider createDefaultDivider() {
- return new BasicSplitPaneDivider(this);
- }
-
- protected Component createDefaultNonContinuousLayoutDivider() {
- return new 1(this);
- }
-
- protected FocusListener createFocusListener() {
- return new FocusHandler(this);
- }
-
- protected ActionListener createKeyboardDownRightListener() {
- return new KeyboardDownRightHandler(this);
- }
-
- protected ActionListener createKeyboardEndListener() {
- return new KeyboardEndHandler(this);
- }
-
- protected ActionListener createKeyboardHomeListener() {
- return new KeyboardHomeHandler(this);
- }
-
- protected ActionListener createKeyboardResizeToggleListener() {
- return new KeyboardResizeToggleHandler(this);
- }
-
- protected ActionListener createKeyboardUpLeftListener() {
- return new KeyboardUpLeftHandler(this);
- }
-
- protected PropertyChangeListener createPropertyChangeListener() {
- return new PropertyHandler(this);
- }
-
- public static ComponentUI createUI(JComponent var0) {
- return new BasicSplitPaneUI();
- }
-
- protected void dragDividerTo(int var1) {
- if (this.getLastDragLocation() != var1) {
- if (this.isContinuousLayout()) {
- this.setDividerLocation(this.splitPane, var1);
- this.setLastDragLocation(var1);
- } else {
- int var2 = this.getLastDragLocation();
- this.setLastDragLocation(var1);
- if (this.orientation == 1) {
- int var3 = this.splitPane.getSize().height;
- if (this.draggingHW) {
- this.nonContinuousLayoutDivider.setLocation(this.getLastDragLocation(), 0);
- } else {
- this.splitPane.repaint(var2, 0, this.dividerSize, var3);
- this.splitPane.repaint(var1, 0, this.dividerSize, var3);
- }
- } else {
- int var4 = this.splitPane.getSize().width;
- if (this.draggingHW) {
- this.nonContinuousLayoutDivider.setLocation(0, this.getLastDragLocation());
- } else {
- this.splitPane.repaint(0, var2, var4, this.dividerSize);
- this.splitPane.repaint(0, var1, var4, this.dividerSize);
- }
- }
- }
- }
-
- }
-
- protected void finishDraggingTo(int var1) {
- this.dragDividerTo(var1);
- this.setLastDragLocation(-1);
- if (!this.isContinuousLayout()) {
- Component var2 = this.splitPane.getLeftComponent();
- Rectangle var3 = var2.getBounds();
- if (this.orientation == 1) {
- int var4 = this.splitPane.getSize().height;
- var2.setSize(var1 - var3.x - this.getDividerBorderSize(), var3.height);
- if (this.draggingHW) {
- this.nonContinuousLayoutDivider.setLocation(-this.dividerSize, 0);
- }
-
- this.splitPane.paintImmediately(var1, 0, this.dividerSize, var4);
- } else {
- int var5 = this.splitPane.getSize().width;
- var2.setSize(var3.width, var1 - var3.y - this.getDividerBorderSize());
- if (this.draggingHW) {
- this.nonContinuousLayoutDivider.setLocation(0, -this.dividerSize);
- }
-
- this.splitPane.paintImmediately(0, var1, var5, this.dividerSize);
- }
-
- this.splitPane.revalidate();
- RepaintManager.currentManager(this.splitPane).validateInvalidComponents();
- this.splitPane.repaint();
- }
-
- this.splitPane.setLastDividerLocation(this.beginDragDividerLocation);
- }
-
- public void finishedPaintingChildren(JSplitPane var1, Graphics var2) {
- if (var1 == this.splitPane && this.getLastDragLocation() != -1 && !this.isContinuousLayout() && !this.draggingHW) {
- Dimension var3 = this.splitPane.getSize();
- var2.setColor(Color.darkGray);
- if (this.orientation == 1) {
- var2.fillRect(this.getLastDragLocation(), 0, this.dividerSize - 1, var3.height - 1);
- } else {
- var2.fillRect(0, this.lastDragLocation, var3.width - 1, this.dividerSize - 1);
- }
- }
-
- }
-
- public BasicSplitPaneDivider getDivider() {
- return this.divider;
- }
-
- protected int getDividerBorderSize() {
- return 1;
- }
-
- public int getDividerLocation(JSplitPane var1) {
- return this.orientation == 1 ? this.divider.getLocation().x : this.divider.getLocation().y;
- }
-
- public Insets getInsets(JComponent var1) {
- return null;
- }
-
- public int getLastDragLocation() {
- return this.lastDragLocation;
- }
-
- public int getMaximumDividerLocation(JSplitPane var1) {
- Dimension var2 = this.splitPane.getSize();
- int var3 = 0;
- Component var4 = this.splitPane.getRightComponent();
- if (var4 != null) {
- Insets var5 = this.splitPane.getInsets();
- Dimension var6 = new Dimension(0, 0);
- if (var4.isVisible()) {
- var6 = var4.getMinimumSize();
- }
-
- if (this.orientation == 1) {
- var3 = var2.width - var6.width;
- } else {
- var3 = var2.height - var6.height;
- }
-
- var3 -= this.dividerSize + this.getDividerBorderSize();
- if (var5 != null) {
- if (this.orientation == 1) {
- var3 += var5.left;
- } else {
- var3 += var5.top;
- }
- }
- }
-
- return Math.max(this.getMinimumDividerLocation(this.splitPane), var3);
- }
-
- public Dimension getMaximumSize(JComponent var1) {
- return this.splitPane != null ? this.layoutManager.maximumLayoutSize(this.splitPane) : new Dimension(0, 0);
- }
-
- public int getMinimumDividerLocation(JSplitPane var1) {
- int var2 = 0;
- Component var3 = this.splitPane.getLeftComponent();
- if (var3 != null && var3.isVisible()) {
- Insets var4 = this.splitPane.getInsets();
- Dimension var5 = var3.getMinimumSize();
- if (this.orientation == 1) {
- var2 = var5.width;
- } else {
- var2 = var5.height;
- }
-
- var2 += this.getDividerBorderSize();
- if (var4 != null) {
- if (this.orientation == 1) {
- var2 += var4.left;
- } else {
- var2 += var4.top;
- }
- }
- }
-
- return var2;
- }
-
- public Dimension getMinimumSize(JComponent var1) {
- return this.splitPane != null ? this.layoutManager.minimumLayoutSize(this.splitPane) : new Dimension(0, 0);
- }
-
- public Component getNonContinuousLayoutDivider() {
- return this.nonContinuousLayoutDivider;
- }
-
- public int getOrientation() {
- return this.orientation;
- }
-
- public Dimension getPreferredSize(JComponent var1) {
- return this.splitPane != null ? this.layoutManager.preferredLayoutSize(this.splitPane) : new Dimension(0, 0);
- }
-
- public JSplitPane getSplitPane() {
- return this.splitPane;
- }
-
- protected void installDefaults() {
- LookAndFeel.installBorder(this.splitPane, "SplitPane.border");
- if (this.divider == null) {
- this.divider = this.createDefaultDivider();
- }
-
- this.divider.setBasicSplitPaneUI(this);
- this.splitPane.setDividerSize((Integer)UIManager.get("SplitPane.dividerSize"));
- this.divider.setDividerSize(this.splitPane.getDividerSize());
- this.splitPane.add(this.divider, "divider");
- this.setOrientation(this.splitPane.getOrientation());
- this.setContinuousLayout(this.splitPane.isContinuousLayout());
- this.resetLayoutManager();
- if (this.nonContinuousLayoutDivider == null) {
- this.setNonContinuousLayoutDivider(this.createDefaultNonContinuousLayoutDivider(), true);
- } else {
- this.setNonContinuousLayoutDivider(this.nonContinuousLayoutDivider, true);
- }
-
- }
-
- protected void installKeyboardActions() {
- this.upKey = KeyStroke.getKeyStroke(38, 0);
- this.splitPane.registerKeyboardAction(this.keyboardUpLeftListener, this.upKey, 1);
- this.downKey = KeyStroke.getKeyStroke(40, 0);
- this.splitPane.registerKeyboardAction(this.keyboardDownRightListener, this.downKey, 1);
- this.leftKey = KeyStroke.getKeyStroke(37, 0);
- this.splitPane.registerKeyboardAction(this.keyboardUpLeftListener, this.leftKey, 1);
- this.rightKey = KeyStroke.getKeyStroke(39, 0);
- this.splitPane.registerKeyboardAction(this.keyboardDownRightListener, this.rightKey, 1);
- this.kpUpKey = KeyStroke.getKeyStroke("KP_UP");
- this.splitPane.registerKeyboardAction(this.keyboardUpLeftListener, this.kpUpKey, 1);
- this.kpDownKey = KeyStroke.getKeyStroke("KP_DOWN");
- this.splitPane.registerKeyboardAction(this.keyboardDownRightListener, this.kpDownKey, 1);
- this.kpLeftKey = KeyStroke.getKeyStroke("KP_LEFT");
- this.splitPane.registerKeyboardAction(this.keyboardUpLeftListener, this.kpLeftKey, 1);
- this.kpRightKey = KeyStroke.getKeyStroke("KP_RIGHT");
- this.splitPane.registerKeyboardAction(this.keyboardDownRightListener, this.kpRightKey, 1);
- this.homeKey = KeyStroke.getKeyStroke(36, 0);
- this.splitPane.registerKeyboardAction(this.keyboardHomeListener, this.homeKey, 1);
- this.endKey = KeyStroke.getKeyStroke(35, 0);
- this.splitPane.registerKeyboardAction(this.keyboardEndListener, this.endKey, 1);
- this.dividerResizeToggleKey = KeyStroke.getKeyStroke(119, 0);
- this.splitPane.registerKeyboardAction(this.keyboardResizeToggleListener, this.dividerResizeToggleKey, 1);
- this.splitPane.registerKeyboardAction(new ToggleSideFocusHandler(this), KeyStroke.getKeyStroke(117, 0), 1);
- }
-
- protected void installListeners() {
- if ((this.propertyChangeListener = this.createPropertyChangeListener()) != null) {
- this.splitPane.addPropertyChangeListener(this.propertyChangeListener);
- }
-
- if ((this.focusListener = this.createFocusListener()) != null) {
- this.splitPane.addFocusListener(this.focusListener);
- }
-
- this.keyboardUpLeftListener = this.createKeyboardUpLeftListener();
- this.keyboardDownRightListener = this.createKeyboardDownRightListener();
- this.keyboardHomeListener = this.createKeyboardHomeListener();
- this.keyboardEndListener = this.createKeyboardEndListener();
- this.keyboardResizeToggleListener = this.createKeyboardResizeToggleListener();
- }
-
- public void installUI(JComponent var1) {
- this.splitPane = (JSplitPane)var1;
- this.dividerLocationIsSet = false;
- this.dividerKeyboardResize = false;
- this.installDefaults();
- this.installListeners();
- this.installKeyboardActions();
- this.setLastDragLocation(-1);
- }
-
- public boolean isContinuousLayout() {
- return this.continuousLayout;
- }
-
- public void paint(Graphics var1, JComponent var2) {
- }
-
- protected void resetLayoutManager() {
- if (this.orientation == 1) {
- this.layoutManager = new BasicHorizontalLayoutManager(this);
- } else {
- this.layoutManager = new BasicVerticalLayoutManager(this);
- }
-
- this.splitPane.setLayout(this.layoutManager);
- this.layoutManager.updateComponents();
- this.splitPane.revalidate();
- this.splitPane.repaint();
- }
-
- public void resetToPreferredSizes(JSplitPane var1) {
- if (this.splitPane != null) {
- this.layoutManager.resetToPreferredSizes();
- this.splitPane.revalidate();
- this.layoutManager.layoutContainer(this.splitPane);
- }
-
- }
-
- public void setContinuousLayout(boolean var1) {
- this.continuousLayout = var1;
- }
-
- public void setDividerLocation(JSplitPane var1, int var2) {
- Component var3 = this.splitPane.getLeftComponent();
- Component var4 = this.splitPane.getRightComponent();
- if (var3 != null && var4 != null) {
- Insets var5 = this.splitPane.getInsets();
- if (var5 != null) {
- if (this.orientation == 1) {
- var3.setSize(Math.max(0, var2 - this.getDividerBorderSize() - var5.left), 10);
- } else {
- var3.setSize(10, Math.max(0, var2 - this.getDividerBorderSize() - var5.top));
- }
- } else if (this.orientation == 1) {
- var3.setSize(Math.max(0, var2 - this.getDividerBorderSize()), 10);
- } else {
- var3.setSize(10, Math.max(0, var2 - this.getDividerBorderSize()));
- }
-
- if (!this.dividerLocationIsSet) {
- this.dividerLocationIsSet = true;
- }
-
- this.splitPane.revalidate();
- this.splitPane.repaint();
- }
-
- }
-
- public void setLastDragLocation(int var1) {
- this.lastDragLocation = var1;
- }
-
- protected void setNonContinuousLayoutDivider(Component var1) {
- this.setNonContinuousLayoutDivider(var1, true);
- }
-
- protected void setNonContinuousLayoutDivider(Component var1, boolean var2) {
- if (this.nonContinuousLayoutDivider != null && this.splitPane != null) {
- this.splitPane.remove(this.nonContinuousLayoutDivider);
- }
-
- this.nonContinuousLayoutDivider = var1;
- if (this.nonContinuousLayoutDivider != null && this.splitPane != null) {
- this.nonContinuousLayoutDivider.setLocation(-1000, -1000);
- Component var3 = this.splitPane.getLeftComponent();
- Component var4 = this.splitPane.getRightComponent();
- int[] var5 = this.layoutManager.getSizes();
- if (var3 != null) {
- this.splitPane.setLeftComponent((Component)null);
- }
-
- if (var4 != null) {
- this.splitPane.setRightComponent((Component)null);
- }
-
- this.splitPane.remove(this.divider);
- this.splitPane.add(this.nonContinuousLayoutDivider, "nonContinuousDivider", this.splitPane.getComponentCount());
- this.splitPane.setLeftComponent(var3);
- this.splitPane.setRightComponent(var4);
- this.splitPane.add(this.divider, "divider");
- if (var2) {
- this.layoutManager.setSizes(var5);
- }
-
- this.splitPane.revalidate();
- this.splitPane.paintImmediately(this.splitPane.getX(), this.splitPane.getY(), this.splitPane.getWidth(), this.splitPane.getHeight());
- }
-
- }
-
- public void setOrientation(int var1) {
- this.orientation = var1;
- }
-
- protected void startDragging() {
- Component var1 = this.splitPane.getLeftComponent();
- Component var2 = this.splitPane.getRightComponent();
- this.beginDragDividerLocation = this.getDividerLocation(this.splitPane);
- this.draggingHW = false;
- ComponentPeer var3;
- if (var1 != null && (var3 = var1.getPeer()) != null && !(var3 instanceof LightweightPeer)) {
- this.draggingHW = true;
- } else if (var2 != null && (var3 = var2.getPeer()) != null && !(var3 instanceof LightweightPeer)) {
- this.draggingHW = true;
- }
-
- if (this.orientation == 1) {
- this.setLastDragLocation(this.divider.getBounds().x);
- this.dividerSize = this.divider.getSize().width + 2 * this.getDividerBorderSize();
- if (!this.isContinuousLayout() && this.draggingHW) {
- this.nonContinuousLayoutDivider.setBounds(this.getLastDragLocation(), 0, this.dividerSize, this.splitPane.getHeight());
- }
- } else {
- this.setLastDragLocation(this.divider.getBounds().y);
- this.dividerSize = this.divider.getSize().height + 2 * this.getDividerBorderSize();
- if (!this.isContinuousLayout() && this.draggingHW) {
- this.nonContinuousLayoutDivider.setBounds(0, this.getLastDragLocation(), this.splitPane.getWidth(), this.dividerSize);
- }
- }
-
- }
-
- protected void uninstallDefaults() {
- if (this.splitPane.getLayout() == this.layoutManager) {
- this.splitPane.setLayout((LayoutManager)null);
- }
-
- if (this.nonContinuousLayoutDivider != null) {
- this.splitPane.remove(this.nonContinuousLayoutDivider);
- }
-
- LookAndFeel.uninstallBorder(this.splitPane);
- this.splitPane.remove(this.divider);
- this.divider.setBasicSplitPaneUI((BasicSplitPaneUI)null);
- this.layoutManager = null;
- this.divider = null;
- this.nonContinuousLayoutDivider = null;
- this.setNonContinuousLayoutDivider((Component)null);
- }
-
- protected void uninstallKeyboardActions() {
- this.splitPane.unregisterKeyboardAction(this.upKey);
- this.splitPane.unregisterKeyboardAction(this.downKey);
- this.splitPane.unregisterKeyboardAction(this.leftKey);
- this.splitPane.unregisterKeyboardAction(this.rightKey);
- this.splitPane.unregisterKeyboardAction(this.homeKey);
- this.splitPane.unregisterKeyboardAction(this.endKey);
- this.splitPane.unregisterKeyboardAction(this.dividerResizeToggleKey);
- this.splitPane.unregisterKeyboardAction(KeyStroke.getKeyStroke(117, 0));
- this.splitPane.unregisterKeyboardAction(this.kpUpKey);
- this.splitPane.unregisterKeyboardAction(this.kpDownKey);
- this.splitPane.unregisterKeyboardAction(this.kpLeftKey);
- this.splitPane.unregisterKeyboardAction(this.kpRightKey);
- this.kpUpKey = this.kpDownKey = this.kpLeftKey = this.kpRightKey = null;
- this.upKey = null;
- this.downKey = null;
- this.leftKey = null;
- this.rightKey = null;
- this.homeKey = null;
- this.endKey = null;
- this.dividerResizeToggleKey = null;
- }
-
- protected void uninstallListeners() {
- if (this.propertyChangeListener != null) {
- this.splitPane.removePropertyChangeListener(this.propertyChangeListener);
- this.propertyChangeListener = null;
- }
-
- if (this.focusListener != null) {
- this.splitPane.removeFocusListener(this.focusListener);
- this.focusListener = null;
- }
-
- this.keyboardUpLeftListener = null;
- this.keyboardDownRightListener = null;
- this.keyboardHomeListener = null;
- this.keyboardEndListener = null;
- this.keyboardResizeToggleListener = null;
- }
-
- public void uninstallUI(JComponent var1) {
- this.uninstallKeyboardActions();
- this.uninstallListeners();
- this.uninstallDefaults();
- this.dividerLocationIsSet = false;
- this.dividerKeyboardResize = false;
- this.splitPane = null;
- }
- }
-